import pickle,os
class Cursor:
    def __init__(self):
        self.data = None
        self.datafile = None
        self.exdata = None
        self.exdatafile = None
    def extract(self):
        if os.path.exists("data.txt"):
            os.remove("data.txt")
        if not os.path.exists("data.db"):
            file = open("data.db","x")
            file.close()
        os.rename("data.db","data.txt")
        with open("data.txt","rb+") as self.exdatafile:
            if not os.path.getsize(os.path.abspath("data.txt")) == 0:
                self.exdata =  pickle.load(self.exdatafile)
                return self.exdata
    def save(self,data):
        self.data = data
        if not os.path.exists("data.txt"):
            file = open("data.txt","x")
            file.close()
        with open("data.txt","wb") as self.datafile:
            pickle.dump(self.data,self.datafile)
            self.datafile.close()
            if os.path.exists("data.db"):
                os.remove("data.db")
            os.rename("data.txt","data.db")

    
    
